# -*- coding: utf-8 -*-
"""
作者: 肖麒
联系方式：QQ：1505448035
时间: 2025/7/24 15:35
文件作用：获取邮件详情接口，mail 由 get_applymail 接口提供， id由 get_getmail 获取
"""
import re

import requests


class GetCode:
    def __init__(self):
        pass

    def get_code(self, mail, time, id):
        headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Pragma": "no-cache",
            "Referer": "http://rootsh.com:8003/",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
        }
        cookies = {
            "mail": mail,
            "time": time,

        }
        url = f"http://rootsh.com:8003/win/{id}"
        # url = "http://rootsh.com:8003/win/9527000(a)mxl001-_-win/0kcsDEIPIMx0DDDeQVIuFW.eml"
        response = requests.get(url, headers=headers, cookies=cookies, verify=False)
        text = response.text
        # captcha_match = re.search(r'验证码：(\d+)', text)
        # if captcha_match:
        #     captcha = captcha_match.group(1)
        #     return f"提取到的验证码是: {captcha}"
        # else:
        #     return "未找到验证码"

        return text


if __name__ == '__main__':
    ocdcaaxyykg4618wqq9rbr_eml_api = GetCode()
    mail = "\"2|1:0|10:1753343415|4:mail|40:NjMzNzA1NjJAbXhsMDAxLndpbnwxNzUzMzQzNDE1|29c651afe67228e6a2b8057fe415e51b832be0073538d144bd4202cf65128ff8\""
    id = "63370562(a)mxl001-_-win/23ydnwBaPuQIX8cMcDPEU8.eml"
    id = 'cNIUAFaJWKUh7kw4nXEKDW.eml'
    response = ocdcaaxyykg4618wqq9rbr_eml_api.get_code(mail, id)
    text = response.text
    # 正则匹配验证码
    verification_code = re.findall(r"输入：\s*<span[^>]*>(\d{6})</span>", text)[0]
    print(verification_code)  # 输出: 457992
